Skip to content

docs: pass an options object to generate() in the T5 and Donut examples - #1961

Open
sarankumar1325 wants to merge 1 commit into
huggingface:mainfrom
sarankumar1325:docs/generate-examples-options-object
Open

sarankumar1325 wants to merge 1 commit into
huggingface:mainfrom
sarankumar1325:docs/generate-examples-options-object

Conversation

@sarankumar1325

Copy link
Copy Markdown

Three JSDoc examples call model.generate() with a tensor as the first argument. generate() takes a single options object (generate({ inputs, ...kwargs })), so these examples fail at runtime:

Example Call Result on @huggingface/transformers 4.3.2 (Node)
AutoModelForSeq2SeqLM (models/auto/modeling_auto.js) model.generate(input_ids) Missing the following inputs: input_ids, attention_mask.
Donut document parsing (donut_swin) model.generate(image_inputs.pixel_values, {...}) Missing the following inputs: pixel_values.
Donut DocVQA (donut_swin) same as above same

Change

The examples now spread the processor/tokenizer outputs into the options object, which is how the other examples in the repo call generate:

const inputs = await tokenizer('translate English to German: I love transformers!');
const outputs = await model.generate({ ...inputs });
const output = await model.generate({
  ...image_inputs,
  decoder_input_ids,
  max_length: model.config.decoder.max_position_embeddings,
});

I spread the whole tokenizer output for T5 because the encoder also needs attention_mask. Passing only { input_ids } still fails with Missing the following inputs: attention_mask.

Verification

I ran the fixed examples in Node with 4.3.2 (dtype: 'q8'):

  • T5: Ich liebe Transformatoren!, which matches the documented output.
  • Donut DocVQA: <s_docvqa><s_question> What is the invoice number?</s_question><s_answer> us-001</s_answer></s>, which matches the documented output.

The CORD-v2 Donut example uses the same call. Prettier passes on both files.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant